import unittest
import requests
import logging
from weidudianying.Tools import Tools


class Wddy(unittest.TestCase):

    def setUp(self) -> None:
        print('开始测试')
        Tools().log()
        # Tools().log2()
        # Tools().log3()

    def tearDown(self) -> None:
        print('结束测试')


    # 内网环境
    login_url = 'http://10.59.9.18/'

    # # 发送邮箱验证码
    # def test_01(self):
    #     t1 = requests.post(url=Wddy.login_url+'movieApi/user/v2/sendOutEmailCode',
    #                        data={'email':'2318636512@qq.com'})
    #     print(t1.json())
    #
    # # 注册
    # def test_02(self):
    #     t1 = requests.post(url=Wddy.login_url + 'movieApi/user/v2/register',
    #                        data={'nickName':'小高先生','pwd':'uNzol1eD+fxXRt/ALcYcdw==','email': '2318636512@qq.com','code':'680267'})
    #     print(t1.json())

    # 登录
    userId = None
    sessionId = None
    def test_wddy_01(self):
        logging.info('开始测试： test_wddy_01')
        r1 = requests.post(url=Wddy.login_url+'movieApi/user/v2/login',data={'email':'2318636512@qq.com','pwd':'uNzol1eD+fxXRt/ALcYcdw=='})
        print(r1.json())
        Wddy.userId = r1.json()['result']['userId']
        print(Wddy.userId)
        Wddy.sessionId = r1.json()['result']['sessionId']
        print(Wddy.sessionId)
        # 断言
        message = r1.json()['message']
        print(message)
        self.assertEqual('登陆成功', message)
        email_dy = r1.json()['result']['userInfo']['email']
        self.assertEqual('2318636512@qq.com', email_dy)
        logging.info('结束测试： test_wddy_01')




    # 查询热门电影列表
    # 电影id
    movieId = None
    def test_wddy_02(self):
        logging.info('开始测试： test_wddy_02')
        r2 = requests.get(url=Wddy.login_url+'movieApi/movie/v2/findHotMovieList',
                          params={'page':1,'count':5})
        print(r2.json())
        Wddy.movieId = r2.json()['result'][0]['movieId']
        print(Wddy.movieId)
        # 断言
        message = r2.json()['message']
        print(message)
        self.assertEqual('查询成功', message)
        logging.info('开始测试： test_wddy_02')